package com.hemerasolutions.v2trainer.model.users;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import com.hemerasolutions.v2trainer.model.base.BaseModel;
import com.hemerasolutions.v2trainer.model.exercise.Equipment;
import com.hemerasolutions.v2trainer.model.interfaces.AgreementHolderInterface;
import com.hemerasolutions.v2trainer.model.interfaces.BaseModelInterface;
import com.hemerasolutions.v2trainer.model.multimedia.Photo;
import com.hemerasolutions.v2trainer.model.others.Theme;


@Entity
public class Academy extends BaseModel implements AgreementHolderInterface,BaseModelInterface  {
 
    private static final long serialVersionUID = 1L;

    @Column(length = 60)
	private String name;

    @Column(length = 50)
	private String owner;

    @Column(length = 18)
	private String cnpj;

    @Column(length = 50)
    private String address;

    @Column(length = 30)
	private String state;

    @Column(length = 30)
	private String city;

    @Column(length = 9)
	private String postalCode;	
    

    @OneToOne(cascade=CascadeType.ALL)
    private User user;
    
    @OneToOne(cascade=CascadeType.ALL,orphanRemoval=true) 
    private Photo logo;

    @OneToOne(cascade=CascadeType.ALL,orphanRemoval=true)
    private Photo wideLogo;    
 
    @ManyToOne
    private Theme theme;
    
    @OneToMany(mappedBy = "academy", cascade=CascadeType.ALL)
	private List<Teacher> teachers;

    @ManyToMany
	private List<Equipment> equipments;

    @ManyToMany(mappedBy = "academys",fetch = FetchType.LAZY)
    private List<Athlete> athletes;
	 
    
	public Academy() {
		super();
		
		this.user 		= new User();
		this.theme	 	= new Theme();
		this.equipments = new ArrayList<Equipment>();
		this.teachers 	= new ArrayList<Teacher>();
		this.athletes 	= new ArrayList<Athlete>();
		this.user.setUserType(User.USERTYPE_ACADEMY);

	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getAddress() {
		return address;
	}

	public String getState() {
		return state;
	}

	public String getCity() {
		return city;
	}

	public String getPostalCode() {
		return postalCode;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public void setState(String state) {
		this.state = state;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public void setPostalCode(String postalCode) {
		this.postalCode = postalCode;
	}


	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getOwner() {
		return owner;
	}

	public void setOwner(String owner) {
		this.owner = owner;
	}

	public String getCnpj() {
		return cnpj;
	}

	public void setCnpj(String cnpj) {
		this.cnpj = cnpj;
	}

	public Photo getLogo() {
		return logo;
	}

	public void setLogo(Photo logo) {
		this.logo = logo;
	}

	public Theme getTheme() {
		return theme;
	}

	public void setTheme(Theme theme) {
		this.theme = theme;
	}

	public List<Equipment> getEquipments() {
		return equipments;
	}

	public void setEquipments(List<Equipment> equipments) {
		this.equipments = equipments;
	}

	public List<Teacher> getTeachers() {
		return teachers;
	}

	public void setTeachers(List<Teacher> teachers) {
		this.teachers = teachers;
	}

	public List<Athlete> getAthletes() {
		return athletes;
	}

	public void setAthletes(List<Athlete> athletes) {
		this.athletes = athletes;
	}

	public Photo getWideLogo() {
		return wideLogo;
	}

	public void setWideLogo(Photo wideLogo) {
		this.wideLogo = wideLogo;
	}



	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((address == null) ? 0 : address.hashCode());
		result = prime * result + ((city == null) ? 0 : city.hashCode());
		result = prime * result + ((cnpj == null) ? 0 : cnpj.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((logo == null) ? 0 : logo.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((owner == null) ? 0 : owner.hashCode());
		result = prime * result
				+ ((postalCode == null) ? 0 : postalCode.hashCode());
		result = prime * result + ((state == null) ? 0 : state.hashCode());
		result = prime * result + ((theme == null) ? 0 : theme.hashCode());
		result = prime * result + ((user == null) ? 0 : user.hashCode());
		result = prime * result
				+ ((wideLogo == null) ? 0 : wideLogo.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Academy other = (Academy) obj;
		if (address == null) {
			if (other.address != null) {
				return false;
			}
		} else if (!address.equals(other.address)) {
			return false;
		}
		if (city == null) {
			if (other.city != null) {
				return false;
			}
		} else if (!city.equals(other.city)) {
			return false;
		}
		if (cnpj == null) {
			if (other.cnpj != null) {
				return false;
			}
		} else if (!cnpj.equals(other.cnpj)) {
			return false;
		}
		if (id == null) {
			if (other.id != null) {
				return false;
			}
		} else if (!id.equals(other.id)) {
			return false;
		}
		if (logo == null) {
			if (other.logo != null) {
				return false;
			}
		} else if (!logo.equals(other.logo)) {
			return false;
		}
		if (name == null) {
			if (other.name != null) {
				return false;
			}
		} else if (!name.equals(other.name)) {
			return false;
		}
		if (owner == null) {
			if (other.owner != null) {
				return false;
			}
		} else if (!owner.equals(other.owner)) {
			return false;
		}
		if (postalCode == null) {
			if (other.postalCode != null) {
				return false;
			}
		} else if (!postalCode.equals(other.postalCode)) {
			return false;
		}
		if (state == null) {
			if (other.state != null) {
				return false;
			}
		} else if (!state.equals(other.state)) {
			return false;
		}
		if (theme == null) {
			if (other.theme != null) {
				return false;
			}
		} else if (!theme.equals(other.theme)) {
			return false;
		}
		if (user == null) {
			if (other.user != null) {
				return false;
			}
		} else if (!user.equals(other.user)) {
			return false;
		}
		if (wideLogo == null) {
			if (other.wideLogo != null) {
				return false;
			}
		} else if (!wideLogo.equals(other.wideLogo)) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "Academy [id=" + id + ", name=" + name + ", owner=" + owner
				+ ", cnpj=" + cnpj + ", address=" + address + ", state="
				+ state + ", city=" + city + ", postalCode=" + postalCode
				+ ", user=" + user + ", logo=" + logo + ", wideLogo="
				+ wideLogo + ", theme=" + theme + "]";
	}

	
}
 
